@extends('admin.layout.base')
@section('title', '全部配置项列表页面')
@section('pluginstyle')
<meta name="csrf-token" content="{{ csrf_token() }}" />
@endsection
@section('content')
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            商品列表页面
        </h1>
        <ol class="breadcrumb">
            <li><a href="{{ url('/admin') }}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">商品管理</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <a class="btn btn-success" href="{{ url('/admin/system/create') }}">
                            <i class="fa fa-plus"></i> 添加配置
                        </a>
                        <div class="box-tools">
                            <form action="{{ url('/admin/system/all') }}" method="get" class="form-inline">
                                <div class="form-group">
                                    <input type="text" name="title" id="msg_title" value="{{ old('msg_title') }}" class="form-control" placeholder="配置名称"/>
                                </div>
                                <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                            </form>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover table-bordered">
                            <tr>
                                <th>#</th>
                                <th>变量名</th>
                                <th>配置名称</th>
                                <th>配置值</th>
                                <th>提示信息</th>
                                <th>排序</th>
                                <th>操作</th>
                            </tr>
                            @foreach($configs as $config)
                            <tr>
                                <td>{{ $config->id }}</td>
                                <td>{{ $config->key }}</td>
                                <td>{{ $config->title }}</td>
                                <td>
                                    @if($config->type == 'string')
                                    <input type="text" name="{{ $config->key }}" id="" value="{{ $config->value }}" /> 
                                    @elseif($config->type == 'textarea')
                                    <textarea name="{{ $config->key }}" id="" cols="50" rows="3">{{ $config->value }}</textarea>
                                    @elseif($config->type == 'radio')
                                        @foreach($config->kv as $k => $v)
                                        <input type="radio" name="{{ $config->key }}" value="{{ $k }}" {{ $config->value == $k ? 'checked' : '' }} />{{ $v }}
                                        @endforeach
                                    @endif
                                </td>
                                <td>{{ $config->tip }}</td>
                                <td>{{ $config->sort }}</td>
                                <td>
                                    <a href="{{ url("/admin/system/{$config->id}/edit") }}" class="btn btn-info">编辑</a>
                                    <a href="{{ url('/admin/system',['id'=>$config->id]) }}" class="btn btn-danger del">删除</a>
                                </td>
                            </tr>
                            @endforeach
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        {!! $configs->appends(['title'=>old('title')])->render() !!}
                    </div>
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
@endsection
@section('pluginscript')
<!-- Slimscroll -->
<script src="{{ asset('/dist/admin/plugins/slimScroll/jquery.slimscroll.min.js') }}"></script>
<!-- FastClick -->
<script src="{{ asset('/dist/admin/plugins/fastclick/fastclick.js') }}"></script>
<script type="text/javascript">
    $(function(){
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        
        // 删除
        $('.del').click(function(){
            var url = $(this).attr('href');
            var tr = $(this).parents('tr');
            var result = confirm('确定要删除？');
            
            if(result){
                $.ajax({
                    url: url,
                    type:'DELETE',
                    success:function(msg){
                        if(msg.status == '1'){
                            tr.remove();
                        } else {
                            alert(msg.info);
                        }
                    }
                });
            }
            return false;
        });
    });
</script>
@endsection